package com.questionnaire.controller;

import com.cloud.beans.ResultBean;
import com.questionnaire.pojo.Paper;
import com.questionnaire.service.PaperService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class PaperController {

    @Autowired
    private PaperService paperService;

    @RequestMapping(value = "/paper/{id}", method = RequestMethod.GET)
    public String index(@PathVariable("id") String paperId, Model model){
        Paper paper = paperService.findPaperWithQuestions(paperId);
        model.addAttribute("paper", paper);
        return "paper/index";
    }

    @ResponseBody
    @RequestMapping(value = "/paper/test", method = RequestMethod.GET)
    public ResultBean<Paper> test(){
        Paper paper = paperService.findPaperWithQuestions("123456");
        return new ResultBean<Paper>(paper);
    }


    @ResponseBody
    @RequestMapping(value = "/paper/save", method = RequestMethod.POST)
    public ResultBean<String> save(){
        return new ResultBean<String>("感谢您的填写");
    }
}
